<?php
/**
 * crcl/base
 *
 * Copyright 2013 CRCL - André Sabosch - info@crcl.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace crcl\base;

interface IValidator
{
  //you can use getInstance (factory)
  //or:

  public static function notEmpty();
  public static function uuid();
  public static function mysqlIdentifier();
}

class Validator extends instance\factory implements IValidator
{
  const TYPE_NOTEMPTY        = 'notempty://';
  const TYPE_UUID            = 'uuid://';
  const TYPE_MYSQLIDENTIFIER = 'mysqlIdentifier://';

  public static function notEmpty()
  {
    return self::getInstance(self::TYPE_NOTEMPTY);
  }

  public static function uuid()
  {
    return self::getInstance(self::TYPE_UUID);
  }

  public static function mysqlIdentifier()
  {
    return self::getInstance(self::TYPE_MYSQLIDENTIFIER);
  }

  public static function getInstance($sUri)
  {
    $sUri = String::getInstance($sUri)
      ->doEndWith('://')
      ->toString();
    return parent::getInstance($sUri);
  }

  /** PROTECTED ***********************************************************************************/

  protected static $sFactoryDirectory = 'validator/container';
  protected static $aFactoryAllowedTypes = array('notempty', 'uuid', 'mysqlIdentifier');
}

/*
  const TYPE_DATETIME = 'Datetime';
  const TYPE_DATE     = 'Date';
  const TYPE_YEAR     = 'Year';
  const TYPE_TIME     = 'Time';
  const TYPE_INTEGER  = 'Integer';
  const TYPE_FLOAT    = 'Float';
  const TYPE_LENGTH   = 'Length';
  const TYPE_MIN      = 'Min';
  const TYPE_URL      = 'Url';
  const TYPE_MAIL     = 'Mail';
  const TYPE_BOOLEAN  = 'Boolean';
*/